package com.personal.common.entity;

import java.io.Serializable;

/**
 * 基础实体类
 * @author zhangqiang
 * create date:2017-2-9
 */
public class BasicEntity implements Serializable{

	private static final long serialVersionUID = 1L;

	protected Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	/**
	 * 重写当前实体类的hashCode()方法
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	/**
	 * 重写当前实体类的equals()方法(两个实体的id相同,两个实体就相同)
	 */
	@Override
	public boolean equals(Object obj) {
		//同一个对象
		if (this == obj){
			return true;
		}
		//为空
		if (obj == null){
			return false;
		}
		//不是同一种类型
		if (getClass() != obj.getClass()){
			return false;
		}
		BasicEntity other = (BasicEntity) obj;
		if (id == null) {
			if (other.id != null){
				return false;
			}
		}else if (!id.equals(other.id)){
			return false;
		}
		return true;
	}
}
